let GM = require('GM');
cc.Class({
    extends: cc.Component,

    properties: {
        //角色刚体节点
        player: cc.Node,

        //游戏UI
        gameUI: cc.Node,

        //满100(御剑飞行能量条)
        _energyFrameCount: {
            type: cc.Integer,
            default: 0,
        },

        //声音
        soundNode: cc.Node,
    },

    start () {
        this.playerControl = this.player.getComponent('panda-control');
        //金币
        this.gold = 0;
        //积分
        this.integral = 0;
        //路程
        this.s = 0;

        this.gameUICtrl = this.gameUI.getComponent('unionButton');
        //声音
        this.sound = this.soundNode.getComponent('sound');

        //控制帧率
        cc.game.setFrameRate(60)
        if(GM.voice == 0){
            this.sound.onStop();
           this.soundNode.parent.active = false;
        }else{
            GM.voice=1;
            this.soundNode.parent.active = true;
        }

    },

    //跳跃
    Jump(){
        this.playerControl.JumpFun();
    },

    //下滑
    Squat(){
        this.playerControl.SquatFun();
    },

    //下滑取消
    unSquat(){
        this.playerControl.unSquatFun();
    },

    //暂停
    stopFun(){
        //GM.start = 2;

        
    },


    addGold(isadd){
        if(!isadd){
            this.gold ++;
            //增加金币
            this.sound.onPlayGold();
            //吃金币加能量条
            this.playerControl.energyFrameCount += 2;
        };

        this.integral = this.s * 10 + this.gold * 100;
        this.gameUICtrl.updateGold(this.integral);
        GM.s = this.integral;
        
    },

    updateS(s) {
        this.s = s;
        this.addGold(true);
        this.gameUICtrl.updateS(this.s);
        GM.distance = this.s;
    },

    updateFly(value){
        this.gameUICtrl.updateFly(value);
    },

    //游戏结束
    over(){
        //积分
        this.integral;
        //路程
        this.s;
        //死亡音效
        this.sound.onPlayDie();
    }
});
